package com.tr.rentcar.model.dao;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tr.rentcar.model.GlobalParamHandler;
import com.tr.rentcar.model.bean.FeedBack;
import com.tr.rentcar.model.bean.FeedBackStyle;
import com.tr.rentcar.model.jdbc.MySqlDb;
import com.tr.rentcar.model.jdbc.ResultHandler;

public class FeedbackDao implements ResultHandler<FeedBack>{
	private MySqlDb db= MySqlDb.getInstance();
	/**
	 * 根据电话模糊查询查询用户反馈内容
	 */
	public List<FeedBack> findTentByTel(String tel) throws SQLException {
		String sql = "select * from  back left join back_style on back.bs_id=back_style.bs_id where back.btel like ?";
		return db.executeQuery(sql,new GlobalParamHandler(tel+"%"),this);
	}
	/**
	 * 查询用户反馈内容
	 */
	public List<FeedBack> findAll() throws SQLException {
		String sql = "select * from  back left join back_style on back.bs_id=back_style.bs_id";
		return db.executeQuery(sql,this);
	}
	/**
	 * 添加用户反馈内容
	 */
	public boolean insertFeedback(String bcontent,int bsid,String buser,String btel) throws SQLException{
		String sql="INSERT INTO `back`(bcontent,bs_id,buser,btel) values(?,?,?,?)";
		return db.executeUpdate(sql,new GlobalParamHandler(bcontent,bsid,buser,btel))>0;
	}
	
	
	@Override
	public FeedBack doHander(Map<String, Object> row) {
		FeedBack fb=new FeedBack();
		Integer bid=Integer.parseInt(row.get("bid")+"") ;
		fb.setBid(bid);
		fb.setBcontent(row.get("bcontent")+"");
		Integer bsid=Integer.parseInt(row.get("bs_id")+"") ;
		fb.setBsId(bsid);
		fb.setBuser(row.get("buser")+"");
		fb.setBdate((Date)row.get("bdate"));
		fb.setBtel(row.get("btel")+"");
		fb.setBsName(row.get("bs_name")+"");
		return fb;
	}
	
}
